package com.ydcycloud.variety.dao.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.smart.mvc.dao.hibernate.JdbcDao;
import com.smart.mvc.model.Pagination;
import com.ydcycloud.variety.dao.SlideShowDao;
import com.ydcycloud.variety.model.SlideShow;
import com.ydcycloud.sys.dao.impl.BaseDaoImpl;

@Component("slideShowDao")
public class SlideShowDaoImpl extends BaseDaoImpl<SlideShow, Integer> implements
		SlideShowDao {
	@Resource
	private JdbcDao baseJdbcDao;

	/**
	 * 获取轮播图
	 * */
	@Override
	public List<Map<String, Object>> getSlideShow() {
		String sql = ("select a.id,a.image_url as imageUrl from slideShow as a "
				+ "where 1=1 group by a.image_url ");
		List<Map<String, Object>> list = baseJdbcDao.findSqlMapQuery(sql);

		return list;
	}

	/**
	 * 分页获取轮播图
	 * */
	@Override
	public Pagination<Map<String, Object>> getSildeShow(Integer pageNo,
			Integer pageSize) {
		String sql = ("select a.id,a.image_url  as imageUrl from slideshow as a where 1=1 "
				+ " group by a.image_url "
				+ "order by a.create_date desc");
		Pagination<Map<String, Object>> p = new Pagination<Map<String, Object>>(
				pageNo, pageSize);
		baseJdbcDao.pageSqlMapQuery(p, sql);
		return p;
	}

	@Override
	public void deleteByIds(String ids) {
		String sql = (" delete from slideshow where id in (" + ids + ") ");
		baseJdbcDao.executeUpdate(sql);
	}

}
